package com.omg.persistence.dao.lifepoint.sqlmapdao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.template.SqlMapDaoTemplate;
import com.omg.persistence.dao.lifepoint.entity.LPUser;
import com.omg.persistence.dao.lifepoint.iface.LPUserDao;

/**
 * 
 * @author xiazhiquan
 * 
 *         May 28, 2011
 */
public class LPUserSqlMapDao extends SqlMapDaoTemplate implements LPUserDao {

	public LPUserSqlMapDao(DaoManager daoManager) {
		super(daoManager);
	}

	@Override
	public LPUser getLPUserByEmail(String email) {
		return (LPUser) this.queryForObject("getLPUserByEmail", email);
	}

	@Override
	public int updateLPUserSid(String userid, String sid) {
		try {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("userid", userid);
			map.put("sid", sid);
			this.update("updateLPUserSid", map);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public LPUser getLPUserByNickname(String nickname) {
		return (LPUser) this.queryForObject("getLPUserByNickname", nickname);
	}

	@Override
	public LPUser getLPUserBySid(String sid) {
		return (LPUser) this.queryForObject("getLPUserBySid", sid);
	}

	@Override
	public LPUser getLPUserByUserid(String userid) {
		return (LPUser) this.queryForObject("getLPUserByUserid", userid);
	}

	@Override
	public int addLPUser(LPUser lpUser) {
		try {
			this.insert("addLPUser", lpUser);
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

	@Override
	public List<LPUser> getLPFriendsByUserid(String userid) {
		return this.queryForList("getLPFriendsByUserid", userid);
	}

	@Override
	public List<LPUser> getAllLPUsers() {
		return this.queryForList("getAllLPUsers");
	}

}
